{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "079f3091",
   "metadata": {},
   "source": [
    "### A：战疫情 5’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccf8d620",
   "metadata": {},
   "source": [
    "【问题描述】\n",
    "\n",
    "为抗击新型冠状病毒感染的肺炎疫情，爱心人士小李花费50000元人民币购买x只口罩，y套防护服。已知x+y的和在区间[20000,21000].\n",
    "\n",
    "请问有多少种购买方案，是刚好花费50000元人民币的!\n",
    "\n",
    "已知口罩价格2元/只，防护服价格100元/套。\n",
    "\n",
    "【答案提交】\n",
    "\n",
    "这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个数字，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a09beee",
   "metadata": {},
   "outputs": [],
   "source": [
    "total = 50000\n",
    "\n",
    "price_mask = 2\n",
    "\n",
    "price_cloth = 100\n",
    "\n",
    "num = 0\n",
    "for i in range(20000, 21000):\n",
    "    if ( total - 2 * i ) % 98 == 0:\n",
    "        num = num + 1\n",
    "        \n",
    "print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85a06864",
   "metadata": {},
   "source": [
    "### B：行动 5’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35f00b7d",
   "metadata": {},
   "source": [
    "【问题描述】\n",
    "\n",
    "小明站在坐标（0, 0）处，面朝 x轴正方向。\n",
    "第一轮，他向前走 1单位距离，然后右转；\n",
    "第二轮，他向前走 2单位距离，然后右转；\n",
    "第三轮，他向前走 3单位距离，然后右转……他一直这么走下去。\n",
    "请问第 2020轮后，他的坐标是：（_________，_________）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f45a45e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "polt = [0, 0]\n",
    "\n",
    "flag = 0\n",
    "for i in range(1, 2020+1):\n",
    "    if flag > 3:\n",
    "        flag = 0 \n",
    "    \n",
    "    if flag == 0:\n",
    "        polt[0] = polt[0] + i\n",
    "        flag = flag+1\n",
    "        continue\n",
    "        \n",
    "    elif flag == 1:\n",
    "        polt[1] = polt[1] - i\n",
    "        flag = flag+1\n",
    "        continue\n",
    "        \n",
    "    elif flag == 2:\n",
    "        polt[0] = polt[0] - i\n",
    "        flag = flag+1\n",
    "        continue\n",
    "        \n",
    "    elif flag == 3:\n",
    "        polt[1] = polt[1] + i\n",
    "        flag = flag+1\n",
    "        continue\n",
    "print(*polt)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5587bd24",
   "metadata": {},
   "source": [
    "### C：莱布尼茨公式 10’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0117474f",
   "metadata": {},
   "source": [
    "【问题描述】\n",
    "\n",
    "   请计算前2020项的值，保留6位小数\n",
    "\n",
    "【答案提交】\n",
    "\n",
    "这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个保留6位的小数，在提交答案时只填写这个小数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e427e018",
   "metadata": {},
   "source": [
    "取反操作，python取反的是按补码取反，即是源码加1再取反\n",
    "flag = (~flag)+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1fb097b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "result = 0\n",
    "\n",
    "flag = 1\n",
    "for i in range(1, 4040, 2):\n",
    "    result = result +  flag * 4 * 1/i \n",
    "    flag = (~flag)+1\n",
    "print('%.6f' % result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27922c2b",
   "metadata": {},
   "source": [
    "### D：价值之和 10’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "639eac2a",
   "metadata": {},
   "source": [
    "【问题描述】\n",
    "\n",
    "定义数字x的价值为其不同质因子的个数。\n",
    "\n",
    "例如:数字2020可以写成2020=2*2*5*101其价值为3\n",
    "\n",
    "JM boy请你帮忙计算整数1到2020中，所有都不包含数字5的正整数的价值之和。\n",
    "\n",
    "【答案提交】\n",
    "\n",
    "这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数（提示：答案最后一位数是奇数）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3cc495e3",
   "metadata": {},
   "source": [
    "### 分解质因数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a5e8b80",
   "metadata": {},
   "outputs": [],
   "source": [
    "res = ''\n",
    "\n",
    "def solve(res,n):\n",
    "    \n",
    "    for i in range(2, n+1):\n",
    "        \n",
    "        if n % i ==0:\n",
    "            \n",
    "            res += str(i)\n",
    "            \n",
    "            n = n // i\n",
    "            \n",
    "            if n == 1:\n",
    "                \n",
    "                return res\n",
    "            \n",
    "            else:\n",
    "                \n",
    "                res += '*'\n",
    "                \n",
    "                return solve(res,n)\n",
    "        else:\n",
    "            continue\n",
    "            \n",
    "print(solve(res,2020))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd1baeda",
   "metadata": {},
   "outputs": [],
   "source": [
    "def solve(res,n):\n",
    "    \n",
    "    for i in range(2, n+1):\n",
    "        \n",
    "        if n % i ==0:\n",
    "            \n",
    "            res.append(i)\n",
    "            \n",
    "            n = n // i\n",
    "            \n",
    "            if n == 1:\n",
    "                \n",
    "                return res\n",
    "            \n",
    "            else:\n",
    "                    \n",
    "                return solve(res,n)\n",
    "            \n",
    "        else:\n",
    "            continue\n",
    "\n",
    "num = 0\n",
    "for i in range(1, 2021):\n",
    "    if '5' not in str(i):\n",
    "        res = list()\n",
    "        solve(res, i)\n",
    "        num = num + len(set(res)) \n",
    "    \n",
    "print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc0b4e91",
   "metadata": {},
   "source": [
    "### E：数方 15’"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3aee5cbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(100, 1000):\n",
    "    if pow(i, 1/3) % 1 == 0:\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e57a16d5",
   "metadata": {},
   "source": [
    "### F：你好，2020"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1a64dc8",
   "metadata": {},
   "source": [
    "2020年，这个年份很特别，2020从中间分成两个整数，大小形状完全一样。\n",
    "\n",
    "小明对形如2020的数字很感兴趣(不包括前导零)，在1到1200中这样的数字包括11、22、33、44、55、66、77、88、99、1010、1111共11个，他们的和是2616\n",
    "\n",
    "请问，在1到n中，所有这样的数的和是多少？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "defe7318",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "\n",
    "result = 0\n",
    "\n",
    "for i in range(1, n+1):\n",
    "    string = str(i)\n",
    "    length = len(string) \n",
    "    if  length % 2 == 0:\n",
    "        if string[:length//2] == string[length//2:]:\n",
    "            \n",
    "            result = result + i\n",
    "        \n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "105394e2",
   "metadata": {},
   "source": [
    "### G：最优值 18’"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5fabd39e",
   "metadata": {},
   "source": [
    "### 组合搭配"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40bfc2b8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "\n",
    "chars = list()\n",
    "\n",
    "for _ in range(n):\n",
    "    chars.extend(list(map(str, input().split())))\n",
    "    \n",
    "def calute(chars):\n",
    "    result = 0\n",
    "    def value():\n",
    "    \n",
    "        return (ord(char[0].upper()) - 64) * len(char) * chars.index(char) \n",
    "    \n",
    "    for char in chars:\n",
    "        \n",
    "        result = result + value()\n",
    "\n",
    "    return result\n",
    "\n",
    "from itertools import product\n",
    "\n",
    "chars = list(product(chars, repeat=n))\n",
    "\n",
    "_chars = chars.copy()\n",
    "\n",
    "for value in chars:\n",
    "    if len(set(chars)) != n:\n",
    "        _chars.remove(value)\n",
    "        \n",
    "        \n",
    "print(_chars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ddfb15ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "from itertools import product\n",
    "l = [1, 2, 3]\n",
    "\n",
    "ll = list(product(l, repeat=3))\n",
    "\n",
    "_ll = ll.copy()\n",
    "for value in ll:\n",
    "    if len(set(value)) != 3:\n",
    "        _ll.remove(value)\n",
    "        \n",
    "print(_ll)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7421713f",
   "metadata": {},
   "source": [
    "### H：计算器 22"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec683754",
   "metadata": {},
   "source": [
    "### J：因数个数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de534b20",
   "metadata": {},
   "source": [
    "描述\n",
    "求所有 2 到 n 的整数中，因数个数第k少的数因数个数是多少。\n",
    "\n",
    "输入\n",
    "第一行两个正整数 n,k即题目描述中的 n,k\n",
    "\n",
    "输出\n",
    "输出仅一行，即因数个数第 k少的数因数个数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e576a0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def solve(res,n):\n",
    "    \n",
    "    for i in range(2, n+1):\n",
    "        \n",
    "        if n % i ==0:\n",
    "            \n",
    "            res.append(i)\n",
    "            \n",
    "            n = n // i\n",
    "            \n",
    "            if n == 1:\n",
    "                \n",
    "                return res\n",
    "            \n",
    "            else:\n",
    "                    \n",
    "                return solve(res,n)\n",
    "            \n",
    "        else:\n",
    "            continue\n",
    "\n",
    "n, k = map(int, input().split())\n",
    "\n",
    "results = list()\n",
    "\n",
    "for i in range(2, n+1):\n",
    "    results.append(list())\n",
    "    \n",
    "    solve(results[-1], i)\n",
    "\n",
    "\n",
    "results = [len(result) for result in results]\n",
    "\n",
    "results.sort()\n",
    "\n",
    "print(results[k])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "lanqiaobei",
   "language": "python",
   "name": "lanqiaobei"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
